<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
<head>
<title>_冲正</title>
<script type="text/javascript">

    
     $(function() {
     });
     
     
     //加载冲正信息
     function openWindow(billItemId){
        $.ajax({
				type : 'post',
				url : '${ctx}/v2/reverse/ajaxQueryItem',
				data : {
					billItemId:billItemId
				},
				dataType : 'json',
				success : function(data) {
					
					var billItem=data.billItem;
					var dutyList=data.dutyList;
					var warehouseList = data.warehouseList;
					var dutyUuid=billItem.dutyUuid;
					var status=billItem.status;
					
					if(status=='undo'){
				       $("#btn_reverse").attr("disabled",false);
				       $("#btn_reverse").attr("value","确定冲正");
				       $("#btn_reverse").attr("class","btn btn-danger");
					}else{
					   $("#btn_reverse").attr("disabled",true);
					   $("#btn_reverse").attr("value","已经冲正");
				       $("#btn_reverse").attr("class","btn");
					}
					
					$("#curId").val(billItem.id);
					$("#customerCode").html(billItem.customer.customerName);
					
					var warehouseCodeHTML = billItem.warehouse.groupName;
					$("#warehouseCode").html(warehouseCodeHTML);
					
					$("#sku").html(billItem.sku);

					var stockCodeHtml = "";
					var boxCodeHtml = "";
					
					if(billItem.stockCode==null||billItem.stockCode==""){
						stockCodeHtml = "<input id='stockCodeValue' style='width:70px;' />";
					}else {
						stockCodeHtml = billItem.stockCode+"<input id='stockCodeValue' type='hidden' style='width:70px;' value='"+billItem.stockCode+"' />";
					}
					if(billItem.boxCode==null||billItem.boxCode==""){
						boxCodeHtml = "<input id='boxCodeValue' style='width:70px;'/>";
					}else {
						boxCodeHtml = billItem.boxCode+"<input id='boxCodeValue' type='hidden'  style='width:70px;' value='"+billItem.boxCode+"' />";
					}
					$("#stockCode").html(stockCodeHtml);
					$("#boxCode").html(boxCodeHtml);
					
					
					$("#salesNumFix").html(billItem.salesNumFix);
					$("#unusedNumFix").html(billItem.unusedNumFix);
					$("#orderNumFix").html(billItem.orderNumFix);
					
					if(billItem.reverser!=null){
					  $("#reverserUuid").html(billItem.reverser.realname);
					}
					
					$("#dutyReason").val(billItem.dutyReason);
					
					$("#dutyUuid").html('');
					var str="<option value=''></option>";
					$.each(dutyList,function(i,item){
					    var uuid=item.jobuuid;
					    if(dutyUuid==uuid){
					        str+="<option selected='selected'  value='"+item.jobuuid+"' >"+item.realname+"</option>";
					    }else{
					         str+="<option  value='"+item.jobuuid+"' >"+item.realname+"</option>";
					    }
					});
					$("#dutyUuid").html(str);
					$("#dutyUuid").trigger("chosen:updated");
				},
				error:function() {
					alert("网络繁忙，请稍后重试...");
				}
			});
        
     }
     
     //冲正
     function reverse(){
      
       
       var itemId=$("#curId").val();
       var dutyUuid=$("#dutyUuid").val();
       var dutyReason=$("#dutyReason").val().trim();
       
       var stockCode=$("#stockCodeValue").val();
       var boxCode=$("#boxCodeValue").val();
       //验证库位
       if(stockCode==''){
          alert("请输入库位");
          $("#stockCodeValue").focus();
          return false;
        }
       //验证箱位
       if(boxCode==''){
          alert("请输入箱位");
          $("#boxCodeValue").focus();
          return false;
        }
         
       //验证责任人
       if(dutyUuid==''){
         alert("请选择责任人");
         $("#dutyUuid").focus();
         return false;
       }
       
       
       //验证责任说明
       if(dutyReason==''){
         alert("请填写责任说明");
         $("#dutyReason").focus();
         return false;
       }
       
       var  btn=$("#btn_reverse");
       btn.attr("disabled",true);
       btn.attr("class","btn");
       
       $.ajax({
			type : 'post',
			url : '${ctx}/v2/reverse/ajaxReverse',
			data : {
				billItemId:itemId,
				dutyUuid:dutyUuid,
				
				stockCode:stockCode,
				boxCode:boxCode,
				
				dutyReason:dutyReason
			},
			dataType : 'json',
			success : function(data) {
			    var msg=data.msg;
			    if(msg=='done'){
			       alert("已经冲正了，请返回查看...");
			    }else if(msg=='nostock'){
			       alert("库存状态异常，请返回查看...");
			    }else if(msg=='success'){
			      alert("冲正成功！");
			      location.reload();
			    }else{
			      alert("网络繁忙，请稍后重试...");
			    }
			    
			    btn.attr("disabled",false);
                btn.attr("class","btn btn-danger");
                
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
				btn.attr("disabled",false);
                btn.attr("class","btn btn-danger");
			}
	   });
       
       
       
       
       
     }



</script>
</head>

<body>
<section class="content">

   <!-- 校对明细 -->
   <div class="box box-solid box-primary" >
	      <div class="box-header">
			<i class="fa fa-th-large"></i>
			<h3 class="box-title">冲正明细</h3>
		 </div> 
	<div class="box-body" >
	
	<table id="stockCodeTable" class="table table-bordered table-condensed" >
		<thead><tr>
		    <th >序号</th>
		    <th >商家</th>
		    <th >仓库</th>
		    <th >sku</th>
		    <th >库位</th>
		    <th >箱位</th>
		    <th >可销售（校对）</th>
		    <th >不可销售（校对）</th>
		    <th >订单占用（校对）</th>
		    <th >责任人</th>
		    <th >冲正人</th>
		    <th >冲正时间</th>
		    <th >状态</th>
		    <th >操作</th>
		    
		</tr></thead>
		
	    <c:forEach items="${itemList}" var="item" varStatus="i">
				<tr id="tr_${item.id}" >
				   <td>${i.count}</td>
				   <td>${item.customer.customerName}</td>
				   <td>${item.warehouse.groupName}</td>
				   <td>${item.sku}</td>
				   <td>${item.stockCode}</td>
				   <td>${item.boxCode}</td>
				   <td>${item.salesNumFix}</td>
				   <td>${item.unusedNumFix}</td>
				   <td>${item.orderNumFix}</td>
				   <td>${item.duter.realname}</td>
				   <td>${item.reverser.realname}</td>
				   <td>${item.reverseTime}</td>
				   <td>
				     <c:if test="${item.status eq 'undo' }"><font color='red'>待冲正</font></c:if>
				     <c:if test="${item.status eq 'done' }"><font color='blue'>已冲正</font></c:if>
				   </td>
				   <td>
				      <c:if test="${item.status eq 'undo' }">
				         <a href="#reverseForm" role="button" data-toggle="modal"  class="btn btn-primary" onclick="openWindow('${item.id}');" >冲正</a>
				      </c:if>
				      
				      <c:if test="${item.status eq 'done' }">
				         <a href="#reverseForm" role="button" data-toggle="modal"  class="btn btn-info" onclick="openWindow('${item.id}');" >查看</a>
				      </c:if>
				       
				   </td>
				</tr>
		</c:forEach>
	 
	 </table>
	</div></div>	
	
	
	<!-- 冲正窗体 start -------------------------------------------------------------------------------------------------->
	<div class="modal fade" id="reverseForm">
	<div class="modal-dialog" style="width: 60%;">
	<div class="modal-content">
	<div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title">冲正处理</h4>
      </div>
		<!-- 体 -->
		<div class="modal-body form-search" style="height:400px;" >
		
		    
		    <div style="height: 330px;" id="changeTable" > 
			<table class="table table-striped table-bordered table-condensed" >
			    <tr>
				    <th >商家</th>
				    <th >仓库</th>
				    <th >sku</th>
				    <th >库位</th>
				    <th >箱位</th>
			    </tr>
			    <tr>
			      <td id="customerCode"></td>
			      <td id="warehouseCode"></td>
			      <td id="sku"></td>
			      <td id="stockCode"></td>
			      <td id="boxCode"></td>
			    </tr>
			    
			    <tr>
				    <th >可销售（校对）</th>
				    <th >不可销售（校对）</th>
				    <th >订单占用（校对）</th>
				    <th >冲正人</th>
				    <th >冲正时间</th>
			    </tr>
			    <tr>
			      <td id="salesNumFix" style="color: red; font-weight: bold;"></td>
			      <td id="unusedNumFix" style="color: red; font-weight: bold;"></td>
			      <td id="orderNumFix" style="color: red; font-weight: bold;"></td>
			      <td id="reverserUuid"></td>
			      <td id="reverseTime"></td>
			    </tr>
			    
			     <tr>
				    <th >责任人</th>
				    <th colspan="4">责任说明</th>
			    </tr>
			    <tr>
			      <td>
			         <select style="width: 150px;" id="dutyUuid" class="form-control">
			         </select>
			      </td>
			      <td colspan="4">
			          <textarea style="width: 400px; height: 100px;" id="dutyReason"></textarea>
			      </td>
			    </tr>
			    
			  </table>
			  </div>
			  
		</div>
		
		<!-- 尾 -->
		<div class="modal-footer">
		    <input type="hidden" id="curId">
			<input id="btn_reverse" class="btn btn-danger"  type="button" value="确定冲正"  onclick="reverse();"/>&nbsp;	
			<input  class="btn" type="button" data-dismiss="modal" value="返回" />
		</div>
		
		
	  </div>
	  </div>	
     </div>
     <!--------冲正窗体 end ----------------------------------------------------------------------------------------------------->

</section>
</body>
</html>
